<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<link rel="STYLESHEET" href="lib.css" type='text/css' />
<link rel="SHORTCUT ICON" href="../icons/pyfav.png" type="image/png" />
<link rel='start' href='../index.html' title='Python documentation Index' />
<link rel="first" href="lib.html" title='Python library Reference' />
<link rel='contents' href='contents.html' title="Contents" />
<link rel='index' href='genindex.html' title='Index' />
<link rel='last' href='about.html' title='About this document...' />
<link rel='help' href='about.html' title='About this document...' />
<link rel="next" href="module-time.html" />
<link rel="prev" href="allos.html" />
<link rel="parent" href="allos.html" />
<link rel="next" href="os-procinfo.html" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name='aesop' content='information' />
<title>14.1 os -- Miscellaneous operating system interfaces</title>
</head>
<body>
<div class="navigation">
<div id='top-navigation-panel' xml:id='top-navigation-panel'>
<table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td class='online-navigation'><a rel="prev" title="14. generic Operating System"
  href="allos.html"><img src='../icons/previous.png'
  border='0' height='32'  alt='Previous Page' width='32' /></a></td>
<td class='online-navigation'><a rel="parent" title="14. generic Operating System"
  href="allos.html"><img src='../icons/up.png'
  border='0' height='32'  alt='Up one Level' width='32' /></a></td>
<td class='online-navigation'><a rel="next" title="14.1.1 process Parameters"
  href="os-procinfo.html"><img src='../icons/next.png'
  border='0' height='32'  alt='Next Page' width='32' /></a></td>
<td align="center" width="100%">Python Library Reference</td>
<td class='online-navigation'><a rel="contents" title="Table of Contents"
  href="contents.html"><img src='../icons/contents.png'
  border='0' height='32'  alt='Contents' width='32' /></a></td>
<td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png'
  border='0' height='32'  alt='Module Index' width='32' /></a></td>
<td class='online-navigation'><a rel="index" title="Index"
  href="genindex.html"><img src='../icons/index.png'
  border='0' height='32'  alt='Index' width='32' /></a></td>
</tr></table>
<div class='online-navigation'>
<b class="navlabel">Previous:</b>
<a class="sectref" rel="prev" href="allos.html">14. Generic Operating System</a>
<b class="navlabel">Up:</b>
<a class="sectref" rel="parent" href="allos.html">14. Generic Operating System</a>
<b class="navlabel">Next:</b>
<a class="sectref" rel="next" href="os-procinfo.html">14.1.1 Process Parameters</a>
</div>
<hr /></div>
</div>
<!--End of Navigation Panel-->

<h1><a name="SECTION0016100000000000000000">
14.1 <tt class="module">os</tt> --
         Miscellaneous operating system interfaces</a>
</h1>

<p>
<a name="module-os"></a>

<p>
This module provides a more portable way of using operating system
dependent functionality than importing a operating system dependent
built-in module like <tt class="module"><a href="module-posix.html">posix</a></tt> or <tt class="module">nt</tt>.

<p>
This module searches for an operating system dependent built-in module like
<tt class="module">mac</tt> or <tt class="module"><a href="module-posix.html">posix</a></tt> and exports the same functions and data
as found there.  The design of all Python's built-in operating system dependent
modules is such that as long as the same functionality is available,
it uses the same interface; for example, the function
<code>os.stat(<var>path</var>)</code> returns stat information about <var>path</var> in
the same format (which happens to have originated with the
POSIX interface).

<p>
Extensions peculiar to a particular operating system are also
available through the <tt class="module">os</tt> module, but using them is of course a
threat to portability!

<p>
Note that after the first time <tt class="module">os</tt> is imported, there is
<em>no</em> performance penalty in using functions from <tt class="module">os</tt>
instead of directly from the operating system dependent built-in module,
so there should be <em>no</em> reason not to use <tt class="module">os</tt>!

<p>
The <tt class="module">os</tt> module contains many functions and data values.
The items below and in the following sub-sections are all available
directly from the <tt class="module">os</tt> module.

<p>
<dl><dt><b><span class="typelabel">exception</span>&nbsp;<tt id='l2h-2577' xml:id='l2h-2577' class="exception">error</tt></b></dt>
<dd>
This exception is raised when a function returns a system-related
error (not for illegal argument types or other incidental errors).
This is also known as the built-in exception <tt class="exception">OSError</tt>.  The
accompanying value is a pair containing the numeric error code from
<tt class="cdata">errno</tt> and the corresponding string, as would be printed by the
C function <tt class="cfunction">perror()</tt>.  See the module
<tt class="module"><a href="module-errno.html">errno</a></tt><a id='l2h-2580' xml:id='l2h-2580'></a>, which contains names for the
error codes defined by the underlying operating system.

<p>
When exceptions are classes, this exception carries two attributes,
<tt class="member">errno</tt> and <tt class="member">strerror</tt>.  The first holds the value of
the C <tt class="cdata">errno</tt> variable, and the latter holds the corresponding
error message from <tt class="cfunction">strerror()</tt>.  For exceptions that
involve a file system path (such as <tt class="function">chdir()</tt> or
<tt class="function">unlink()</tt>), the exception instance will contain a third
attribute, <tt class="member">filename</tt>, which is the file name passed to the
function.
</dd></dl>

<p>
<dl><dt><b><tt id='l2h-2578' xml:id='l2h-2578'>name</tt></b></dt>
<dd>
The name of the operating system dependent module imported.  The
following names have currently been registered: <code>'posix'</code>,
<code>'nt'</code>, <code>'mac'</code>, <code>'os2'</code>, <code>'ce'</code>,
<code>'java'</code>, <code>'riscos'</code>.
</dd></dl>

<p>
<dl><dt><b><tt id='l2h-2579' xml:id='l2h-2579'>path</tt></b></dt>
<dd>
The corresponding operating system dependent standard module for pathname
operations, such as <tt class="module">posixpath</tt> or <tt class="module">macpath</tt>.  Thus,
given the proper imports, <code>os.path.split(<var>file</var>)</code> is
equivalent to but more portable than
<code>posixpath.split(<var>file</var>)</code>.  Note that this is also an
importable module: it may be imported directly as
<tt class="module"><a href="module-os.path.html">os.path</a></tt>.
</dd></dl>

<p>

<p><br /></p><hr class='online-navigation' />
<div class='online-navigation'>
<!--Table of Child-Links-->
<a name="CHILD_LINKS"><strong>Subsections</strong></a>

<ul class="ChildLinks">
<li><a href="os-procinfo.html">14.1.1 Process Parameters</a>
<li><a href="os-newstreams.html">14.1.2 File Object Creation</a>
<li><a href="os-fd-ops.html">14.1.3 File Descriptor Operations</a>
<li><a href="os-file-dir.html">14.1.4 Files and Directories</a>
<li><a href="os-process.html">14.1.5 Process Management</a>
<li><a href="os-path.html">14.1.6 Miscellaneous System Information</a>
<li><a href="os-miscfunc.html">14.1.7 Miscellaneous Functions</a>
</ul>
<!--End of Table of Child-Links-->
</div>

<div class="navigation">
<div class='online-navigation'>
<p></p><hr />
<table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td class='online-navigation'><a rel="prev" title="14. generic Operating System"
  href="allos.html"><img src='../icons/previous.png'
  border='0' height='32'  alt='Previous Page' width='32' /></a></td>
<td class='online-navigation'><a rel="parent" title="14. generic Operating System"
  href="allos.html"><img src='../icons/up.png'
  border='0' height='32'  alt='Up one Level' width='32' /></a></td>
<td class='online-navigation'><a rel="next" title="14.1.1 process Parameters"
  href="os-procinfo.html"><img src='../icons/next.png'
  border='0' height='32'  alt='Next Page' width='32' /></a></td>
<td align="center" width="100%">Python Library Reference</td>
<td class='online-navigation'><a rel="contents" title="Table of Contents"
  href="contents.html"><img src='../icons/contents.png'
  border='0' height='32'  alt='Contents' width='32' /></a></td>
<td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png'
  border='0' height='32'  alt='Module Index' width='32' /></a></td>
<td class='online-navigation'><a rel="index" title="Index"
  href="genindex.html"><img src='../icons/index.png'
  border='0' height='32'  alt='Index' width='32' /></a></td>
</tr></table>
<div class='online-navigation'>
<b class="navlabel">Previous:</b>
<a class="sectref" rel="prev" href="allos.html">14. Generic Operating System</a>
<b class="navlabel">Up:</b>
<a class="sectref" rel="parent" href="allos.html">14. Generic Operating System</a>
<b class="navlabel">Next:</b>
<a class="sectref" rel="next" href="os-procinfo.html">14.1.1 Process Parameters</a>
</div>
</div>
<hr />
<span class="release-info">Release 2.5.1, documentation updated on 18th April, 2007.</span>
</div>
<!--End of Navigation Panel-->
<address>
See <i><a href="about.html">About this document...</a></i> for information on suggesting changes.
</address>
</body>
</html>
